﻿using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZFY.Core;

namespace ZFY.AspNetCore
{
    public static class StaticInfo
    {
        public static string ContentRootPath;
        public static string WebRootPath;
    }

    public class ReuseMethod
    {
        public static void ImageFormatCheck(string imageNmae)
        {
            var imageFormat = new string[] { "jpg", "gif", "ico", "png" };
            var fileFormat = imageNmae.Substring(imageNmae.LastIndexOf(".") + 1);
            if (!imageFormat.Contains(fileFormat))
            {
                throw new ZFYException("图片格式错误");
            }
        }
        public static async System.Threading.Tasks.Task<byte[]> GetFileBufferAsync(IFormFile file)
        {
            var buffer = new byte[file.Length];
            var stream = file.OpenReadStream();
            await stream.ReadAsync(buffer, 0, (int)file.Length);
            return buffer;
        }
    }
}
